def greet():
    """打印问候语 (无参数无返回值)"""
    print("Hello, Word")



greet()

def get_pi():
    """返回圆周率(无参数有返回值)"""
    return 3.2425936
pi = get_pi()
print(f"圆周率: {pi:.2f}")


def power(base,exponent):
    """计算幂 (位置参数必须按逆序传递)"""
    return base ** exponent

print(power(2, 3))
print(power(3, 2))


def divide(divided, divisor):
    """除法运算 (明确指定参数ming)"""
    return divided /divisor

print(divide(divisor=2, divided=10))



def greet(name, greeting="Hello"):
    """带默认值的问候函数"""
    return f"{greeting}, {name}!"


print(greet("Alice"))
print(greet("Bob","Hi"))




def sum_all(*numbers):
    """求任意数量的数字和"""
    total = 0
    for num in numbers:
        total += num
    return total

print(sum_all(1,2,3,))
print(sum_all(1,2,3,4,5))


def print_info(**details):
    """打印键值对信息"""
    for key ,value in details.items():
        print(f"{key}: {value}")

print_info(name="Alice", age=25, city="New York")



def analyze_numbers(numbers):
    """返回列表的最大值、最小值和平均值"""
    return max(numbers), min(numbers), sum(numbers)/len(numbers)


max_num, min_num, avg = analyze_numbers([4, 2, 9, 5])
print(f"最大值: {max_num}, 最小值: {min_num}, 平均值: {avg:.1f}")


def make_multiplier(factor):
    """生成一个乘数函数"""
    def multiplier(x):
        return x * factor
    return multiplier

double = make_multiplier(2)
print(double(5))

def no_return():
    """没有return语句的函数"""
    pass

result = no_return()
print(result)


def add_item(item, items=[]):
    items.append(item)
    return items

print(add_item(1))
print(add_item(2))


def add_item_fixed(item, items=None):
    items = items or []
    items.appenf(item)
    return items


def mixed_args(a, b, c=0, *args, **kwargs):
    print(f"a={a}, b={b}, c={c}, args={args}, kwargs={kwargs}")

mixed_args(1,2,3,4,5, name="Alice")

def convert_temp(temp, from_scale='c', to_scale='f'):
    """温度单位转换
    Args:
        temp: 温度值
        from_scale: 原单位('c'-摄氏, 'f'-华氏, 'k'-开尔文)
        to_scale: 目标单位
    Returns:
        转换后的温度值
    """
    if from_scale.lower() == 'f':
        celsius = (temp - 32) * 5 / 9
    elif from_scale.lower() == 'k':
        celsius = temp -273.15
    else:
        celsius = temp


print(f"37°C → {convert_temp(37,'c','f'):.1f}°F")
print(f"212°F → {convert_temp(212,'f','k'):.1f}K")





def is_palindrome(s):
    """检查字符串是否为回文(忽略大小和空格)"""
    s = ''.join(c.lower() for c in s if c.isalnum())
    return s == s[::-1]

print(is_palindrome("A man, a plan, a canal: Panama"))













